import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";

export const newsApi = createApi({
  reducerPath: "newsApi",
  baseQuery: fetchBaseQuery({
    baseUrl: "https://newsapi.org/v2/everything",
  }),
  endpoints: (builder) => ({
    getNewsByCompanyName: builder.query({
      query: (company) => ({
        url: `?q=${company}&apiKey=${
          import.meta.env.VITE_NEWS_API
        }&pageSize=10`,
      }),
    }),
  }),
});

export const { useLazyGetNewsByCompanyNameQuery } = newsApi;
